package com.kaifamiao.www.demo.do0905;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class Test {
    public static void main(String[] args) {

    }
    public static void trans(){
        Connection conn = null;
        PreparedStatement statement = null;
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/bank","root","");
            //老兵转出100
            String sql = "UPDATE customer SET balance = balance + ? WHERE customer_name = ?";
            statement.setObject(1,-100);
            statement.setObject(2,"老兵");
            statement.executeUpdate();   //执行给定的SQL语句
            System.out.println("老兵转出成功");
            //新兵转入100
            sql = "update customer set balance = balance + ? where customer_name = ?";
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
